package com.tianji.promotion.config;

import com.tianji.common.autoconfigure.xxljob.XxlJobProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author: 19311
 * @CreateTime: 2025-03-29
 * @Description: 促销配置类
 * @Version: 1.0
 */
@Slf4j
@Configuration
public class PromotionConfig {

    @Bean
    public Executor exchangeCodeExecutor() {
        ThreadPoolTaskExecutor  executor = new ThreadPoolTaskExecutor();
        // 配置核心线程数
        executor.setCorePoolSize(2);
        // 配置最大线程数
        executor.setMaxPoolSize(5);
        // 队列大小
        executor.setQueueCapacity(200);
        // 线程名称
        executor.setThreadNamePrefix("exchange-code-handler-");
        // 拒绝策略(老板执行，也就是从异步变成同步执行)
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}
